package com.example.mall.web.controller;

import com.example.mall.domain.AlipayInfo;
import com.example.mall.dto.AlipayInfoDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.AlipayInfoQuery;
import com.example.mall.query.PageDTO;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IAlipayInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/alipayInfo")
public class AlipayInfoController {

    @Autowired
    public IAlipayInfoService alipayInfoService;

    /**
     * 分页查询支付宝支付信息表信息
     * @param alipayInfoQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付宝支付信息表信息",notes = "分页查询支付宝支付信息表信息",httpMethod = "GET")
    public JSONResult queryPage(AlipayInfoQuery alipayInfoQuery){
        PageDTO<AlipayInfoDto> alipayInfoDtoPageDTO = alipayInfoService.queryPage(alipayInfoQuery);
        return JSONResult.success("查询成功",alipayInfoDtoPageDTO);
    }

    /**
     * 根据id查询支付宝支付信息表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询支付宝支付信息表信息",notes = "根据id查询支付宝支付信息表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.ALIPAY_INFO_NOT_ID);
        }
        AlipayInfo alipayInfo = alipayInfoService.getById(id);
        return JSONResult.success("查询成功",alipayInfo);
    }

    /**
     * 根据id查询支付宝支付信息表信息
     * @param id
     * @return
     */
    @GetMapping("queryAlipayInfoById/{id}")
    @ApiOperation(value = "根据id查询支付宝支付信息表信息",notes = "根据id查询支付宝支付信息表信息",httpMethod = "GET")
    public JSONResult queryAlipayInfoById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.ALIPAY_INFO_NOT_ID);
        }
        AlipayInfo alipayInfo = alipayInfoService.queryAlipayInfoById(id);
        return JSONResult.success("查询成功",alipayInfo);
    }

    /**
     * 查询全部支付宝支付信息表信息
     * @param
     * @return
     */
    @GetMapping("queryAlipayInfoList")
    @ApiOperation(value = "查询全部支付宝支付信息表信息",notes = "查询全部支付宝支付信息表信息",httpMethod = "GET")
    public JSONResult queryAlipayInfoList(){
        List<AlipayInfo> alipayInfos = alipayInfoService.queryAlipayInfoList();
        return JSONResult.success("查询成功",alipayInfos);
    }

    /**
     * 新增支付宝支付信息表
     * @param alipayInfoDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付宝支付信息表",notes = "新增支付宝支付信息表",httpMethod = "POST")
    public JSONResult insert(@RequestBody AlipayInfoDto alipayInfoDto){
        alipayInfoService.insert(alipayInfoDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付宝支付信息表信息
     * @param alipayInfoDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付宝支付信息表信息",notes = "修改支付宝支付信息表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody AlipayInfoDto alipayInfoDto){
        alipayInfoService.update(alipayInfoDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付宝支付信息表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除支付宝支付信息表信息",notes = "删除支付宝支付信息表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        alipayInfoService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付宝支付信息表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付宝支付信息表信息",notes = "批量删除支付宝支付信息表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        alipayInfoService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
